<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
  "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
  <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    
    <title>gozerlib.persist.pdod &mdash; GOZERWAVE v0.1 BETA documentation</title>
    <link rel="stylesheet" href="../../_static/default.css" type="text/css" />
    <link rel="stylesheet" href="../../_static/pygments.css" type="text/css" />
    <script type="text/javascript">
      var DOCUMENTATION_OPTIONS = {
        URL_ROOT:    '../../',
        VERSION:     '0.1 BETA',
        COLLAPSE_MODINDEX: false,
        FILE_SUFFIX: '.html',
        HAS_SOURCE:  true
      };
    </script>
    <script type="text/javascript" src="../../_static/jquery.js"></script>
    <script type="text/javascript" src="../../_static/doctools.js"></script>
    <link rel="top" title="GOZERWAVE v0.1 BETA documentation" href="../../index.html" />
    <link rel="next" title="gozerlib.persist.pdol" href="pdol.html" />
    <link rel="prev" title="gozerlib.persist.mempersist" href="mempersist.html" /> 
  </head>
  <body>
    <div class="related">
      <h3>Navigation</h3>
      <ul>
        <li class="right" style="margin-right: 10px">
          <a href="../../genindex.html" title="General Index"
             accesskey="I">index</a></li>
        <li class="right" >
          <a href="../../modindex.html" title="Global Module Index"
             accesskey="M">modules</a> |</li>
        <li class="right" >
          <a href="pdol.html" title="gozerlib.persist.pdol"
             accesskey="N">next</a> |</li>
        <li class="right" >
          <a href="mempersist.html" title="gozerlib.persist.mempersist"
             accesskey="P">previous</a> |</li>
        <li><a href="../../index.html">GOZERWAVE v0.1 BETA documentation</a> &raquo;</li> 
      </ul>
    </div>  

    <div class="document">
      <div class="documentwrapper">
        <div class="bodywrapper">
          <div class="body">
            
  <div class="section" id="module-gozerlib.persist.pdod">
<h1>gozerlib.persist.pdod<a class="headerlink" href="#module-gozerlib.persist.pdod" title="Permalink to this headline">¶</a></h1>
<p>pickled dicts of dicts</p>
<dl class="class">
<dt id="gozerlib.persist.pdod.Pdod">
<em class="property">class </em><tt class="descclassname">gozerlib.persist.pdod.</tt><tt class="descname">Pdod</tt><big>(</big><em>filename</em>, <em>default={}</em><big>)</big><a class="headerlink" href="#gozerlib.persist.pdod.Pdod" title="Permalink to this definition">¶</a></dt>
<dd><p>Bases: <a title="gozerlib.persist.persist.Persist" class="reference external" href="persist.html#gozerlib.persist.persist.Persist"><tt class="xref docutils literal"><span class="pre">gozerlib.persist.persist.Persist</span></tt></a></p>
<p>pickled dicts of dicts.</p>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
<tr class="field"><th class="field-name">Parameters:</th><td class="field-body"><ul class="first last simple">
<li><em>filename</em> (string) &#8211; filename to store data in</li>
<li><em>default</em> (dict, list , string, integer or None) &#8211; data to initialise pdod with</li>
</ul>
</td>
</tr>
</tbody>
</table>
<dl class="method">
<dt id="gozerlib.persist.pdod.Pdod.get">
<tt class="descname">get</tt><big>(</big><em>name1</em>, <em>name2</em><big>)</big><a class="headerlink" href="#gozerlib.persist.pdod.Pdod.get" title="Permalink to this definition">¶</a></dt>
<dd><p>get data[name1][name2].</p>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
<tr class="field"><th class="field-name">Parameters:</th><td class="field-body"><ul class="first simple">
<li><em>name1</em> (string) &#8211; first key</li>
<li><em>name2</em> (string) &#8211; second key</li>
</ul>
</td>
</tr>
<tr class="field"><th class="field-name">Return type:</th><td class="field-body"><p class="first last">dict, list, string, integer or None</p>
</td>
</tr>
</tbody>
</table>
</dd></dl>

<dl class="method">
<dt id="gozerlib.persist.pdod.Pdod.has_key">
<tt class="descname">has_key</tt><big>(</big><em>name</em><big>)</big><a class="headerlink" href="#gozerlib.persist.pdod.Pdod.has_key" title="Permalink to this definition">¶</a></dt>
<dd><p>has name key.</p>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
<tr class="field"><th class="field-name">Parameter:</th><td class="field-body"><em>name</em> (string) &#8211; key name</td>
</tr>
<tr class="field"><th class="field-name">Return type:</th><td class="field-body">boolean</td>
</tr>
</tbody>
</table>
</dd></dl>

<dl class="method">
<dt id="gozerlib.persist.pdod.Pdod.has_key2">
<tt class="descname">has_key2</tt><big>(</big><em>name1</em>, <em>name2</em><big>)</big><a class="headerlink" href="#gozerlib.persist.pdod.Pdod.has_key2" title="Permalink to this definition">¶</a></dt>
<dd><p>has [name1][name2] key.</p>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
<tr class="field"><th class="field-name">Parameters:</th><td class="field-body"><ul class="first simple">
<li><em>name1</em> (string) &#8211; first key name</li>
<li><em>name2</em> &#8211; second key name</li>
</ul>
</td>
</tr>
<tr class="field"><th class="field-name">Return type:</th><td class="field-body"><p class="first last">boolean</p>
</td>
</tr>
</tbody>
</table>
</dd></dl>

<dl class="method">
<dt id="gozerlib.persist.pdod.Pdod.save">
<tt class="descname">save</tt><big>(</big><big>)</big><a class="headerlink" href="#gozerlib.persist.pdod.Pdod.save" title="Permalink to this definition">¶</a></dt>
<dd>save data to database.</dd></dl>

<dl class="method">
<dt id="gozerlib.persist.pdod.Pdod.set">
<tt class="descname">set</tt><big>(</big><em>name1</em>, <em>name2</em>, <em>item</em><big>)</big><a class="headerlink" href="#gozerlib.persist.pdod.Pdod.set" title="Permalink to this definition">¶</a></dt>
<dd><p>set name, name2 item</p>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
<tr class="field"><th class="field-name">Parameters:</th><td class="field-body"><ul class="first simple">
<li><em>name1</em> (string) &#8211; first key</li>
<li><em>name2</em> (string) &#8211; second key</li>
<li><em>item</em> (dict, list, string, integer or None) &#8211; data to set</li>
</ul>
</td>
</tr>
<tr class="field"><th class="field-name">Return type:</th><td class="field-body"><p class="first last">None</p>
</td>
</tr>
</tbody>
</table>
</dd></dl>

<dl class="method">
<dt id="gozerlib.persist.pdod.Pdod.setdefault">
<tt class="descname">setdefault</tt><big>(</big><em>name</em>, <em>default</em><big>)</big><a class="headerlink" href="#gozerlib.persist.pdod.Pdod.setdefault" title="Permalink to this definition">¶</a></dt>
<dd><p>set default of name.</p>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
<tr class="field"><th class="field-name">Parameters:</th><td class="field-body"><ul class="first simple">
<li><em>name</em> (string) &#8211; name of item to set default for</li>
<li><em>default</em> (dict, list, string, integer or None) &#8211; data to set</li>
</ul>
</td>
</tr>
<tr class="field"><th class="field-name">Return type:</th><td class="field-body"><p class="first last">dict, list, string, integer or None</p>
</td>
</tr>
</tbody>
</table>
</dd></dl>

</dd></dl>

<div class="section" id="code">
<h2>code<a class="headerlink" href="#code" title="Permalink to this headline">¶</a></h2>
<div class="highlight-python"><table class="highlighttable"><tr><td class="linenos"><pre>  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162</pre></td><td class="code"><div class="highlight"><pre><span class="c"># gozerlib/persist/pdod.py</span>
<span class="c">#</span>
<span class="c">#</span>

<span class="sd">&quot;&quot;&quot; pickled dicts of dicts &quot;&quot;&quot;</span>

<span class="kn">from</span> <span class="nn">persist</span> <span class="kn">import</span> <span class="n">Persist</span>
 
<span class="k">class</span> <span class="nc">Pdod</span><span class="p">(</span><span class="n">Persist</span><span class="p">):</span>

    <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        pickled dicts of dicts.</span>

<span class="sd">        :param filename: filename to store data in</span>
<span class="sd">        :type filename: string</span>
<span class="sd">        :param default: data to initialise pdod with</span>
<span class="sd">        :type default: dict, list , string, integer or None</span>

<span class="sd">    &quot;&quot;&quot;</span>

    <span class="k">def</span> <span class="nf">__init__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">filename</span><span class="p">,</span> <span class="n">default</span><span class="o">=</span><span class="p">{}):</span>
        <span class="n">Persist</span><span class="o">.</span><span class="n">__init__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">filename</span><span class="p">)</span>

        <span class="k">if</span> <span class="ow">not</span> <span class="bp">self</span><span class="o">.</span><span class="n">data</span><span class="p">:</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">data</span> <span class="o">=</span> <span class="p">{}</span>

    <span class="k">def</span> <span class="nf">__getitem__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">name</span><span class="p">):</span>

        <span class="sd">&quot;&quot;&quot; return item with name. &quot;&quot;&quot;</span>

        <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">data</span><span class="o">.</span><span class="n">has_key</span><span class="p">(</span><span class="n">name</span><span class="p">):</span>
            <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">data</span><span class="p">[</span><span class="n">name</span><span class="p">]</span>

    <span class="k">def</span> <span class="nf">save</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>

        <span class="sd">&quot;&quot;&quot; save data to database. &quot;&quot;&quot;</span>

        <span class="n">Persist</span><span class="o">.</span><span class="n">save</span><span class="p">(</span><span class="bp">self</span><span class="p">)</span>

    <span class="k">def</span> <span class="nf">__delitem__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">name</span><span class="p">):</span>

        <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">            delete name item. </span>

<span class="sd">            :param name: name of item to delete</span>
<span class="sd">            :type name: string</span>

<span class="sd">        &quot;&quot;&quot;</span>

        <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">data</span><span class="o">.</span><span class="n">has_key</span><span class="p">(</span><span class="n">name</span><span class="p">):</span>
            <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">data</span><span class="o">.</span><span class="n">__delitem__</span><span class="p">(</span><span class="n">name</span><span class="p">)</span>

    <span class="k">def</span> <span class="nf">__setitem__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">name</span><span class="p">,</span> <span class="n">item</span><span class="p">):</span>

        <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">             set name item. </span>

<span class="sd">            :param name: name of item to set</span>
<span class="sd">            :type name: string</span>
<span class="sd">            :param item: data to set</span>
<span class="sd">            :type item: dict, list, string, integer or None</span>
<span class="sd">            :rtype: None</span>

<span class="sd">        &quot;&quot;&quot;</span>

        <span class="bp">self</span><span class="o">.</span><span class="n">data</span><span class="p">[</span><span class="n">name</span><span class="p">]</span> <span class="o">=</span> <span class="n">item</span>

    <span class="k">def</span> <span class="nf">__contains__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">name</span><span class="p">):</span>

        <span class="sd">&quot;&quot;&quot; </span>
<span class="sd">            check if data is available. </span>

<span class="sd">            :param name: key to check for</span>
<span class="sd">            :type name: string</span>
<span class="sd">            :rtype: boolean</span>

<span class="sd">        &quot;&quot;&quot;</span>

        <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">data</span><span class="o">.</span><span class="n">__contains__</span><span class="p">(</span><span class="n">name</span><span class="p">)</span>

    <span class="k">def</span> <span class="nf">setdefault</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">name</span><span class="p">,</span> <span class="n">default</span><span class="p">):</span>

        <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">            set default of name.</span>

<span class="sd">            :param name: name of item to set default for</span>
<span class="sd">            :type name: string</span>
<span class="sd">            :param default: data to set</span>
<span class="sd">            :type default: dict, list, string, integer or None</span>
<span class="sd">            :rtype: dict, list, string, integer or None</span>
<span class="sd">            </span>
<span class="sd">        &quot;&quot;&quot;</span>

        <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">data</span><span class="o">.</span><span class="n">setdefault</span><span class="p">(</span><span class="n">name</span><span class="p">,</span> <span class="n">default</span><span class="p">)</span>

    <span class="k">def</span> <span class="nf">has_key</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">name</span><span class="p">):</span>

        <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">            has name key. </span>

<span class="sd">            :param name: key name</span>
<span class="sd">            :type name: string</span>
<span class="sd">            :rtype: boolean</span>
<span class="sd"> </span>
<span class="sd">        &quot;&quot;&quot;</span>

        <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">data</span><span class="o">.</span><span class="n">has_key</span><span class="p">(</span><span class="n">name</span><span class="p">)</span>

    <span class="k">def</span> <span class="nf">has_key2</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">name1</span><span class="p">,</span> <span class="n">name2</span><span class="p">):</span>

        <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">            has [name1][name2] key. </span>

<span class="sd">            :param name1: first key name</span>
<span class="sd">            :type name1: string</span>
<span class="sd">            :param name2: second key name</span>
<span class="sd">            :type name3: string</span>
<span class="sd">            :rtype: boolean</span>

<span class="sd">        &quot;&quot;&quot;</span>

        <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">data</span><span class="o">.</span><span class="n">has_key</span><span class="p">(</span><span class="n">name1</span><span class="p">):</span>
            <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">data</span><span class="p">[</span><span class="n">name1</span><span class="p">]</span><span class="o">.</span><span class="n">has_key</span><span class="p">(</span><span class="n">name2</span><span class="p">)</span>

    <span class="k">def</span> <span class="nf">get</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">name1</span><span class="p">,</span> <span class="n">name2</span><span class="p">):</span>

        <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">            get data[name1][name2].</span>

<span class="sd">            :param name1: first key</span>
<span class="sd">            :type name1: string</span>
<span class="sd">            :param name2: second key</span>
<span class="sd">            :type name2: string</span>
<span class="sd">            :rtype: dict, list, string, integer or None</span>

<span class="sd">        &quot;&quot;&quot;</span>

        <span class="k">try</span><span class="p">:</span>
            <span class="n">result</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">data</span><span class="p">[</span><span class="n">name1</span><span class="p">][</span><span class="n">name2</span><span class="p">]</span>
            <span class="k">return</span> <span class="n">result</span>
        <span class="k">except</span> <span class="ne">KeyError</span><span class="p">:</span>
            <span class="k">return</span> <span class="bp">None</span>

    <span class="k">def</span> <span class="nf">set</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">name1</span><span class="p">,</span> <span class="n">name2</span><span class="p">,</span> <span class="n">item</span><span class="p">):</span>

        <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">            set name, name2 item </span>

<span class="sd">            :param name1: first key</span>
<span class="sd">            :type name1: string</span>
<span class="sd">            :param name2: second key</span>
<span class="sd">            :type name2: string</span>
<span class="sd">            :param item: data to set</span>
<span class="sd">            :type item: dict, list, string, integer or None</span>
<span class="sd">            :rtype: None</span>

<span class="sd">        &quot;&quot;&quot;</span>

        <span class="k">if</span> <span class="ow">not</span> <span class="bp">self</span><span class="o">.</span><span class="n">data</span><span class="o">.</span><span class="n">has_key</span><span class="p">(</span><span class="n">name1</span><span class="p">):</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">data</span><span class="p">[</span><span class="n">name1</span><span class="p">]</span> <span class="o">=</span> <span class="p">{}</span>

        <span class="bp">self</span><span class="o">.</span><span class="n">data</span><span class="p">[</span><span class="n">name1</span><span class="p">][</span><span class="n">name2</span><span class="p">]</span> <span class="o">=</span> <span class="n">item</span>
</pre></div>
</td></tr></table></div>
</div>
</div>


          </div>
        </div>
      </div>
      <div class="sphinxsidebar">
        <div class="sphinxsidebarwrapper">
            <h3><a href="../../index.html">Table Of Contents</a></h3>
            <ul>
<li><a class="reference external" href="">gozerlib.persist.pdod</a><ul>
<li><a class="reference external" href="#code">code</a></li>
</ul>
</li>
</ul>

            <h4>Previous topic</h4>
            <p class="topless"><a href="mempersist.html"
                                  title="previous chapter">gozerlib.persist.mempersist</a></p>
            <h4>Next topic</h4>
            <p class="topless"><a href="pdol.html"
                                  title="next chapter">gozerlib.persist.pdol</a></p>
            <h3>This Page</h3>
            <ul class="this-page-menu">
              <li><a href="../../_sources/gozerlib/persist/pdod.txt"
                     rel="nofollow">Show Source</a></li>
            </ul>
          <div id="searchbox" style="display: none">
            <h3>Quick search</h3>
              <form class="search" action="../../search.html" method="get">
                <input type="text" name="q" size="18" />
                <input type="submit" value="Go" />
                <input type="hidden" name="check_keywords" value="yes" />
                <input type="hidden" name="area" value="default" />
              </form>
              <p class="searchtip" style="font-size: 90%">
              Enter search terms or a module, class or function name.
              </p>
          </div>
          <script type="text/javascript">$('#searchbox').show(0);</script>
        </div>
      </div>
      <div class="clearer"></div>
    </div>
    <div class="related">
      <h3>Navigation</h3>
      <ul>
        <li class="right" style="margin-right: 10px">
          <a href="../../genindex.html" title="General Index"
             >index</a></li>
        <li class="right" >
          <a href="../../modindex.html" title="Global Module Index"
             >modules</a> |</li>
        <li class="right" >
          <a href="pdol.html" title="gozerlib.persist.pdol"
             >next</a> |</li>
        <li class="right" >
          <a href="mempersist.html" title="gozerlib.persist.mempersist"
             >previous</a> |</li>
        <li><a href="../../index.html">GOZERWAVE v0.1 BETA documentation</a> &raquo;</li> 
      </ul>
    </div>
    <div class="footer">
      &copy; Copyright 2009, Bart Thate.
      Last updated on Nov 14, 2009.
      Created using <a href="http://sphinx.pocoo.org/">Sphinx</a> 0.6.3.
    </div>
  </body>
</html>